package com.czh.intelligentoj.model.enums;

import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 题目提交后，判题信息枚举
 *
 * @author CZH
 * 
 */
public enum JudageInfoMeaasgeEnum {

    ACCEPTED("成功", "accepted"),
    WRONG_ANSWER("答案错误", "wrong"),
    COMPILE_ERROR("compile error", "编译错误"),
    MEMORY_LIMIT_ERROR("memory limit", "内存超限"),
    TIME_LIMIT_ERROR("time limit", "时间超限"),
    PRESENTATION_ERROR("presentation error", "输出格式错误"),
    WARNING("warning", "等待中"),
    OUTPUT_LIMIT_EXCEEDE("output limit", "输出超限"),
    DANGEROUS_OPERATION("dangerous input", "危险操作"),
    RUNTIME_ERROR("runtime error", "运行时错误"),
    SYSTEM_ERROR("system error", "系统错误");


    private final String text;

    private final String value;

    JudageInfoMeaasgeEnum(String text, String value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static JudageInfoMeaasgeEnum getEnumByValue(String value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (JudageInfoMeaasgeEnum anEnum : JudageInfoMeaasgeEnum.values()) {
            if (anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }

    public String getValue() {
        return value;
    }

    public String getText() {
        return text;
    }
}
